// Bus_BPA.cpp: implementation of the CBus_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Dat/Bus_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBus_BPA::CBus_BPA()
{
	m_chType = 'B';
	m_chSubType = ' ';
	m_chChangeCode = ' ';

	m_dPGen = 0;
	m_dPLoad = 0;
	m_dPMax = 0;
	m_dPShunt = 0;
	m_dQLoad = 0;
	m_dQMin = 0;
	m_dQSchedMax = 0;
	m_dQShunt = 0;
	m_dRBkV = 0;
	m_dVarsSppld = 0;
	m_dVmax = 0;
	m_dVmin = 0;
	m_chType = 'B';

	memset(m_strRBName,' ',8);
	m_strRBName[8] = '\0';
	memset(m_strZone,' ',2);
	m_strZone[2] = '\0';

	m_strCardType[0] = 'B';
}

CBus_BPA::CBus_BPA(CBus_BPA &busBPA):CNode_BPA(busBPA)
{
	m_dPGen = busBPA.m_dPGen;
	m_dPLoad = busBPA.m_dPLoad;
	m_dPMax = busBPA.m_dPMax;
	m_dPShunt = busBPA.m_dPShunt;
	m_dQLoad = busBPA.m_dQLoad;
	m_dQMin = busBPA.m_dQMin;
	m_dQSchedMax = busBPA.m_dQSchedMax;
	m_dQShunt = busBPA.m_dQShunt;
	m_dRBkV = busBPA.m_dRBkV;
	m_dVarsSppld = busBPA.m_dVarsSppld;
	m_dVmax = busBPA.m_dVmax;
	m_dVmin = busBPA.m_dVmin;
	m_chType = busBPA.m_chType;

	strcpy(m_strRBName,busBPA.m_strRBName);
	strcpy(m_strZone,busBPA.m_strZone);	
}

CBus_BPA::~CBus_BPA()
{

}

bool CBus_BPA::FillEx(char *buffer)
{
	int i;
//	printf("CBus_BPA::FillEx\n");
	bool bResult = CNode_BPA::FillEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CBus_BPA: FillEx): no basic information!\n");
		return false;
	}
	
	if (strlen(buffer)<19)
		return bResult;
	
	for(i=0;i<2;i++)
	{
		if(!buffer[18+i])
			break;
		else
			m_strZone[i] = buffer[18+i];
	}
	m_strZone[2] = '\0';
	if(i!=2)
		return true;

	m_dPLoad = StrToDouble(&buffer[20],5);
	if(EndOfSec(&buffer[20],5))
		return true;

	m_dQLoad = StrToDouble(&buffer[25],5);
	if(EndOfSec(&buffer[25],5))
		return true;

	m_dPShunt = StrToDouble(&buffer[30],4);
	if(EndOfSec(&buffer[30],4))
		return true;
	
	m_dQShunt = StrToDouble(&buffer[34],4);
	if(EndOfSec(&buffer[34],4))
		return true;

	m_dPMax = StrToDouble(&buffer[38],4);
	if(EndOfSec(&buffer[38],4))
		return true;

	m_dPGen = StrToDouble(&buffer[42],5);
	if(EndOfSec(&buffer[42],5))
		return true;

	m_dQSchedMax = StrToDouble(&buffer[47],5);
	if(EndOfSec(&buffer[47],5))
		return true;

	m_dQMin = StrToDouble(&buffer[52],5);
	if(EndOfSec(&buffer[52],5))
		return true;

	m_dVmax = StrToDouble(&buffer[57],4,3);
	if(EndOfSec(&buffer[57],4))
		return true;

	m_dVmin = StrToDouble(&buffer[61],4,3);
	if(EndOfSec(&buffer[61],4))
		return true;

	for(i=0;i<8;i++)
	{
		if(!buffer[65+i])
			break;
		else
			m_strRBName[i] = buffer[65+i];
	}
	m_strRBName[8] = '\0';
	if(i!=8)
		return true;

	m_dRBkV = StrToDouble(&buffer[73],4);
	if(EndOfSec(&buffer[73],4))
		return true;

	m_dVarsSppld = StrToDouble(&buffer[77],3);
	
	return true;
}


bool CBus_BPA::UpdateEx(char *buffer)
{
	bool bResult = CNode_BPA::UpdateEx(buffer);
	
	if (!bResult)
	{
		printf("Error in (CBus_BPA: UpdateEx): impossible!\n");
		return false;
	}

	strcpy(&buffer[18],m_strZone);
	DoubleToStr(m_dPLoad,&buffer[20],5);
	DoubleToStr(m_dQLoad,&buffer[25],5);
	DoubleToStr(m_dPShunt,&buffer[30],4);
	DoubleToStr(m_dQShunt,&buffer[34],4);
	DoubleToStr(m_dPMax,&buffer[38],4);
	DoubleToStr(m_dPGen,&buffer[42],5);
	DoubleToStr(m_dQSchedMax,&buffer[47],5);
	DoubleToStr(m_dQMin,&buffer[52],5);
	DoubleToStr(m_dVmax,&buffer[57],4,3);
	DoubleToStr(m_dVmin,&buffer[61],4,3);
	strcpy(&buffer[65],m_strRBName);
	DoubleToStr(m_dRBkV,&buffer[73],4);
	DoubleToStr(m_dVarsSppld,&buffer[77],3);
	
	return true;
}
